package com.wngz.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wngz.dto.ComputersDto;
import com.wngz.entity.Computers;
import com.wngz.mapper.ComputersMapper;
import com.wngz.service.ComputersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Objects;

@Service
public class ComputersServiceImpl implements ComputersService {
    @Autowired
    private ComputersMapper computersMapper;

    @Override
    public IPage<Computers> queryEmployees(ComputersDto computersDto) {
        LambdaQueryWrapper<Computers> queryWrapper = new LambdaQueryWrapper<>();

        queryWrapper.like(StringUtils.hasText(computersDto.getBrand()),Computers::getBrand,computersDto.getBrand())
                .eq(Objects.nonNull(computersDto.getPrice()),Computers::getPrice,computersDto.getPrice());

        Page<Computers> objectPage = new Page<>(computersDto.getPageNumber(),computersDto.getPageSize());

        computersMapper.selectPage(objectPage,queryWrapper);

        return objectPage;
    }

    @Override
    public void update(Computers computers) {
        computersMapper.updateById(computers);
    }

    @Override
    public void remove(Integer id) {
        computersMapper.deleteById(id);
    }


}
